<template>
  <BasicCard>
    <BasicVxeTable v-bind="gridOptions"> </BasicVxeTable>
  </BasicCard>
</template>

<script setup lang="ts">
  import dayjs from 'dayjs'
  import { columns, columnsPlatform, columnsStack } from '../data'
  import { splitTsIdToTime } from '@/utils'
  import { getDaBaoJiPingZhongJiLu } from '@/api/shuJuBaoBiao'

  const props = defineProps({
    type: {
      type: String,
      default: 'winding'
    }
  })
  const { t } = useI18n()

  const varietyEnum = {
    winding: [columns, 1, '络筒'],
    platform: [columnsPlatform, 2, '平台'],
    stack: [columnsStack, 3, '垛位']
  }

  const gridOptions = reactive<BasicGridProps>({
    extraConfig: {
      title: t(`custom.${varietyEnum[props.type][2]}品种报表`),
      isCustom: false,
      isExport: false,
      isFilterAndSort: true
    }, // 拓展的配置
    id: `shujubaobiao-${props.type}`, // id用于缓存,务必配置
    height: '100%',
    loading: true,
    columns: varietyEnum[props.type][0],
    toolbarConfig: {} // 工具栏
  })

  const getList = () => {
    getDaBaoJiPingZhongJiLu({
      TsIdStart: 25072202,
      TsIdEnd: 25072202,
      id: varietyEnum[props.type][1]
    })
      .then((res: any) => {
        gridOptions.loading = false
        gridOptions.data = res
          .map((value) => {
            return {
              tsid: splitTsIdToTime(value.tsid) + ' ' + value.banCi,
              packerName: value.packerName,
              materialName: value.materialName,
              time: value.time == null ? null : dayjs(value.time).format('YYYY-MM-DD HH:mm:ss'),
              thirdMaterialColorDescription:
                value.materialName == null ? '' : value.thirdMaterialColorDescription,
              duoWei: value.duoWei,
              pinZhong: value.pinZhong,
              materialColor: value.materialColor,
              lineNum: value.lineNum,
              pingTaiHao: value.lineNum + '-' + (value.duoWei == null ? '' : value.duoWei),
              duoWeiHao: value.lineNum + '-' + (value.duoWei == null ? '' : value.duoWei)
            }
          })
          .sort((a, b) => {
            return a.duoWei - b.duoWei
          })
      })
      .catch(() => {
        gridOptions.loading = false
      })
  }

  onMounted(() => {
    getList()
  })
</script>
